package com.guan.ioc.controller;

import com.guan.ioc.config.UserConfig;
import com.guan.ioc.model.UserInfo;
import com.guan.ioc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class UserController2 {

    private UserService userService;

    private UserConfig userConfig;

    private UserInfo userInfo;

//    public UserController2() {
//    }

    // 构造方法注入
//    @Autowired
//    public UserController2(UserService userService) {
//        this.userService = userService;
//    }

    @Autowired
    public UserController2(UserService userService, UserConfig userConfig, @Qualifier("user1")UserInfo userInfo) {
        this.userService = userService;
        this.userConfig = userConfig;
        this.userInfo = userInfo;
    }

    public UserController2(UserService userService, UserConfig userConfig) {
        this.userService = userService;
        this.userConfig = userConfig;
    }

    public void sayHi() {
        userService.doService();
        userConfig.doConfig();
        System.out.println(userInfo);
        System.out.println("UserController sayHi...");
    }

}
